package yaty.lee.ssh2.action;

import yaty.lee.ssh2.model.Person;
import yaty.lee.ssh2.service.PersonService;

import com.opensymphony.xwork2.ActionSupport;

public class PersonSaver extends ActionSupport {
	private static final long serialVersionUID = 8578349342211617514L;
	private transient PersonService personService;
	private Person person;

	@Override
	public String execute() throws Exception {
		personService.save(person);
		return SUCCESS;
	}

	@Override
	public void validate() {
		if (person.getFirst_name().length() == 0) {
			addFieldError("person.first_name", "First name is required.");
		}
		if (person.getLast_name().length() == 0) {
			addFieldError("person.last_name", "Last name is required.");
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

}
